/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fir;

import java.io.*;
import java.net.*;
import javax.swing.*;

/**
 *
 * @author zhangyucen
 */
public class ServerThread extends Thread {

    boolean connected = false;
    Window chess;

    public ServerThread(Window che) {
        chess = che;
    }

    public void run() {
        if (!connected) {
            try {
                chess.serversocket = new ServerSocket(chess.serverport);
                //chess.frame.setTitle("Waiting for client...");
                chess.setTitle("五子棋（Waiting for client...）");
                chess.conn = chess.serversocket.accept();
                connected = true;
                chess.in = chess.conn.getInputStream();
                chess.out = chess.conn.getOutputStream();
                chess.wait = false;
                chess.NetPlay = true;
                chess.player1 = true;
                chess.player2 = false;
                chess.setThread();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, "Network error!", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}
